<template>
    <orh-table reload  @on-reload="refresh"
        pages :pageDate="pageDate"
        search :searchOption="typelist"
        :searchOptionSelected="searchOptionSelected"
        @on-search='searchmt'
        @on-page-change="queryData">
        <current-term @on-formstate="formState" style="width:200px" slot="option"></current-term>
        <Table :columns="columns" :data="data" :loading="tableload" slot="table"></Table>
    </orh-table>
</template>

<script>

export default {
    components: {
        CurrentTerm: resolve=> require(['&/Authpub/CurrentTerm.vue'],resolve)
    },
    name: "leave-allstudentleave",
    data () {
        return {
            listUrl:null,
            tableload:true,
            pageDate: {
                total: 0,
                current_page: 1,
                per_page: 0
            },
            data:[],
            allid:'',
            columns:[
                {
                    title: '序号',
                    type: 'index',
                    width: 60,
                    align: 'center'
                },
                {
                    title: '学生姓名',
                    align:'center',
                    render: (h, params) => {
                        return h('div', params.row.student!=null?`${params.row.student.student_name.zh}(${params.row.student.identityard_num})`:'');
                    }
                },
                {
                    title: '班级',
                    align:'center',
                    render: (h, params) => {
                        return h('div', params.row.eclass!=null?params.row.eclass.eclass_name.zh:'');
                        }
                },
                {
                    title: '请假种类',
                    align:'center',
                    render: (h, params) => {
                        return h('div', params.row.student_leave_kinds.dictionary_name.zh);
                    }
                },
                {
                    title: '请假开始时间',
                    align:'center',
                    key:'start_time',
                },
                {
                    title: '请假结束时间',
                    align:'center',
                    key:'end_time',
                },
                {
                    title: '审核状态',
                    align:'center',
                    render: (h, params) => {
                        let col='';
                        let name='';
                        if(params.row.status== '0'){
                            col='red';
                            name='未审核';
                        }else if(params.row.status== '1'){
                            col='green';
                            name='通过';
                        }else if(params.row.status== '2'){
                            col='red';
                            name='未通过';
                        }else{
                            col='';
                            name='不需要审核';
                        }
                        return h('div', [
                            h('div',{
                                style: {
                                color: col,
                                },
                            }, name)
                        ]);
                    }
                },
            ],
            searchOptionSelected: 'student_name',
            typelist:[
                {
                    value: 'student_name',
                    label: '学生'
                },
                {
                    value: 'class',
                    label: '班级'
                },
            ],
        }
    },

    methods: {
        /************************************************************
         * 获取所有学生请假数据
         ************************************************************/
        queryData(index){
            this.tableload = true
            this.$http.get(`${this.listUrl}${index}`).then(val=>{
                this.data = val.data.data
                if(val.pages!=null){
                    this.pageDate.per_page = val.data.per_page
                    this.pageDate.total = val.data.total
                    this.pageDate.current_page = val.data.current_page
                }
                this.tableload = false
            }).catch(err => {
                if (err.code && err.code == 422) {
                    this.$Message.error(err.message);
                }
                this.tableload = false
            })
        },
        /************************************************************
         * 查询
         ************************************************************/
        searchmt(val,type) {
            this.listUrl=`api/leave/v1/student_leave/allstudent_leave?semester_id=${this.allid}&searchtype=${type}&searchvalue=${val}&page=`
            this.queryData(1)
        },
        /************************************************************
         * 重新请求数据
         ************************************************************/
        requery(state){
            if(state == true){
                this.show = false
                this.queryData(this.pageDate.current_page)
            }
        },
        /************************************************************
         * 刷新数据
         ************************************************************/
        refresh(){
            this.listUrl=`api/leave/v1/student_leave/allstudent_leave?semester_id=${this.allid}&page=`
            this.queryData(1)
        },
        /************************************************************
         * 选择学期
         ************************************************************/
        formState(val){
            if(val!=null){
                this.allid = val
                this.listUrl=`api/leave/v1/student_leave/allstudent_leave?semester_id=${this.allid}&page=`
                this.queryData(this.pageDate.current_page)
            }
        },
    },
}
</script>
